<?php
require_once('conexion_db.php');
require_once('auxiliares.php');
require_once('smarty/libs/Smarty.class.php');


session_save_path('sessions/');
session_name('operacion');
session_cache_expire(15);
session_start();



// LOGOUT
if( isset($_GET["logout"]) ){
	$_SESSION['permisos']=0;
	header('Location: login.php');
	exit;
}

// LOGIN
if( !empty($_POST['email']) && !empty($_POST['pass'])){

	
	$r = mysql_query("select id_user from users where email='".mysql_real_escape_string($_POST['email'])."' and pass= MD5('".mysql_real_escape_string($_POST['pass'])."')") or die(mysql_error());
	if( $rs = mysql_fetch_array($r) ){
		$_SESSION["usuario_email"] = $_POST['email'] ;
		$_SESSION['id_user'] = $rs['id_user'];
                $_SESSION['permisos'] = 1;
		
		header('Location: agenda_listado.php');
		exit;
	}else{
		$_SESSION['permisos'] = 0 ;
		$error = "Wrong Username or Password.\\nAccess denied.";
	}
}



# Template smarty
$oTpl = createObjSmarty();
$msj = (isset($_GET['action']) && $_GET['action']=='restricted' ) ? "Necesita Loguearse para acceder a la p&aacute;gina solicitada." : "" ;
$oTpl->assign('mensaje', $msj);
$oTpl->display('tpl/login.html');
?>
